package com.coreJava.chapter6;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

public class DailyCounter {
    private static int count = 0;
    private static LocalDate currentDate;
    private static LocalDate previousDate;

    public static String getBatch() {
        currentDate = LocalDate.now();

        // 如果是新的一天，重置计数器
        if (!currentDate.equals(previousDate)) {
            count = 0;
        }

        // 增加计数器
        count++;

        // 更新上一次的日期
        previousDate = currentDate;

        // 左补零 10 -> 00010
        String value = StringUtils.leftPad(String.valueOf(count), 5, "0");

        //时间戳 后面拼接流水号 如果需要  可以加上时分秒
        String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date());

        String patch = datetime + value;
        return patch;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {

            String batch = getBatch();
            System.out.println(batch);
        }
    }
}
